package com.yswy.backstage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yswy.backstage.service.DomainCertificateService;
import com.yswy.backstage.service.TgDeductionService;
import com.yswy.domain.entity.DomainCertificate;
import com.yswy.domain.entity.tf.TgDeduction;
import com.yswy.domain.entity.tf.TgEvent;
import com.yswy.domain.vo.dto.BaseFilter;
import com.yswy.domain.vo.gld.addOrUpate.DomainCertificateAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.TgDeductionAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.base.BaseReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/tgDeduction")
@Api(tags = "扣量配置")
public class TgDeductionController {

    @Autowired
    private TgDeductionService tgDeductionService;


    @PostMapping("/pageTgDeduction")
    @ApiOperation(value = "扣量配置列表")
    public Page<TgDeduction> pageTgDeduction(@RequestBody  BaseFilter req, HttpServletRequest request) {
        return tgDeductionService.pageTgDeduction(req);
    }

    @GetMapping("/listTgDeduction")
    @ApiOperation(value = "扣量配置列表")
    public List<TgDeduction> listTgDeduction(@RequestParam(value = "tgDeductionId" , required = false) Long tgDeductionId
                                  , HttpServletRequest request) {
        return tgDeductionService.listTgDeduction(tgDeductionId);
    }


    @GetMapping("/isExist")
    @ApiOperation(value = "判断扣量配置是否存在")
    public Boolean isExist(@RequestParam(value = "identifier") String identifier,
                        HttpServletRequest request) {
        return tgDeductionService.isExist(identifier);
    }


    @PostMapping("/addTgDeduction")
    @ApiOperation(value = "添加扣量配置")
    public void addTgDeduction(@RequestBody @Validated(BaseReqVO.CREATE.class) TgDeductionAddOrUpdate req, HttpServletRequest request) {
        tgDeductionService.addOrUpadteTgDeduction(req);
    }

    @PostMapping("/upadteTgDeduction")
    @ApiOperation(value = "修改扣量配置")
    public void upadteTgDeduction(@RequestBody @Validated(BaseReqVO.UPDATE.class) TgDeductionAddOrUpdate req, HttpServletRequest request) {
        tgDeductionService.addOrUpadteTgDeduction(req);
    }

    @GetMapping("/delTgDeduction")
    @ApiOperation(value = "删除扣量配置")
    public void delTgDeduction(@RequestParam(value = "tgDeductionId") Long tgDeductionId,
                                   HttpServletRequest request) {
        tgDeductionService.delTgDeduction(tgDeductionId);
    }


}
